#include <string>
#include "utility/Singleton.h"
#include "thread/current_thread.h"
#include "thread/Thread.h"

class Test 
{
 public:
  Test()
  {
    printf("tid=%d, constructing %p\n", CurrentThread::tid(), this);
  }

  ~Test()
  {
    printf("tid=%d, destructing %p %s\n", CurrentThread::tid(), this, name_.c_str());
  }

  const std::string& name() const { return name_; }
  void setName(const std::string& n) { name_ = n; }

 private:
  std::string name_;
};

void threadFunc()
{
  printf("tid=%d, %p name=%s\n",
         CurrentThread::tid(),
         &Singleton<Test>::INSTANCE(),
         Singleton<Test>::INSTANCE().name().c_str());
  Singleton<Test>::INSTANCE().setName("only one, changed");
}

int main()
{
  Singleton<Test>::INSTANCE().setName("only one");
  Thread t1(threadFunc);
  t1.start();
  t1.join();
  printf("tid=%d, %p name=%s\n",
         CurrentThread::tid(),
         &Singleton<Test>::INSTANCE(),
         Singleton<Test>::INSTANCE().name().c_str());
}
